//
//  NSString+FDSpell.m
//  FamousDoctorOnline
//
//  Created by 张睿 on 16/7/7.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "NSString+FDSpell.h"

@implementation NSString (FDSpell)

//转拼音
- (NSString *)transToSpell{
    NSMutableString * mutableString = [NSMutableString stringWithString:self];
    CFStringTransform((CFMutableStringRef) mutableString, NULL, kCFStringTransformToLatin, false);
    mutableString = (NSMutableString *)[mutableString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:[NSLocale currentLocale]];
    mutableString = [[mutableString stringByReplacingOccurrencesOfString:@"" withString:@""] mutableCopy];
    
    return mutableString.lowercaseString;
}

//拼音首字母
- (NSString *)transToSpellFirstCase{
    NSMutableString * stringM = [NSMutableString string];
    
    NSString *temp  =  nil;
    for(int i =0; i < [self length]; i++){
        
        temp = [self substringWithRange:NSMakeRange(i, 1)];
        
        NSMutableString *mutableString=[NSMutableString stringWithString:temp];
        
        CFStringTransform((CFMutableStringRef)mutableString,NULL,kCFStringTransformToLatin,false);
        
        mutableString = (NSMutableString*)[mutableString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:[NSLocale currentLocale]];
        
        mutableString =  [[mutableString substringToIndex:1] mutableCopy];
        
        [stringM appendString:(NSString *)mutableString];
        
    }
    
    return stringM.lowercaseString;

    
}

@end
